/**
 * Created by LeungZ on 2016/3/24.
 */
import './header.scss';
import temp from './header.html';
import k8sDtlCtrl from '../../pages/alarm/k8s/detail/detail.ctrl.js';
import k8sDtlView from '../../pages/alarm/k8s/detail/detail.html';


class HeaderDrct {
    constructor() {
        this.replace = true;
        this.restrict = 'E';
        this.scope = {};
        this.templateUrl = temp;
        this.controllerAs = 'header';
    }
    
    controller($uiModal, alarmSrv, $rootScope, uiNotification, userSrv,$location) {
        "ngInject";
        this.userName = $rootScope.user.sysUserCode;

        alarmSrv.getHeadAlarmOfK8s().then(data=> {
            this.k8salarm = data.list;
            this.k8stotal = data.count;
        }).catch(function (data) {
            uiNotification.error({
                title: '告警推送通知',
                message: '获取告警数据有误'
            });
        });

        this.openDetailOfK8s = function (alarm) {
            $uiModal.open({
                animation: true,
                templateUrl: k8sDtlView,
                controller: k8sDtlCtrl,
                controllerAs: 'dtl',
                resolve: {
                    alarm: function () {
                        alarm.isActive = !!alarm.isActive;
                        return alarm;
                    }
                }
            });
        };

        this.logout = function () {
            userSrv.logOut().catch(data=>{
                uiNotification.error({
                    title: '用户退出',
                    message: data.resultMsg
                });
            })
        }
    }

    static factory() {
        return new HeaderDrct();
    }

}
export default HeaderDrct